﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace WindowsGame1
{
    class Actor3d
    {
        public Vector3 position;
        public Vector3 direction;
        Model mModel;

        //public bool ignoreGravity = false;
        public bool readyToexit = false;

        public Actor3d(ContentManager content,String model) {
            mModel = content.Load<Model>(model);
        }

        public void update(int dTime)
        {
            position += direction;//Posicion final sea igual a posicion inicial + direccion

        }

        public void Draw(SpriteBatch sb)
        {
            Matrix[] transforms = new Matrix[mModel.Bones.Count];
            mModel.CopyAbsoluteBoneTransformsTo(transforms);
            Vector3 cam = new Vector3(0.0f,0.0f,-2.0f);

            foreach (ModelMesh mesh in mModel.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(1) * Matrix.CreateTranslation(position);
                    effect.View = Matrix.CreateLookAt(cam, position, Vector3.Up);
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), 800 / 600, 1.0f, 10000.0f);
                }
                mesh.Draw();
            }
        }

        public void SetDirection(float xdir, float ydir, float zdir)
        {
            direction.X = xdir;
            direction.Y = ydir;
            direction.Z = zdir;
        }

        public void SetDirection(Vector3 dir)
        {
            direction.X = dir.X;
            direction.Y = dir.Y;
            direction.Z = dir.Z;
        }

        public void SetPosition(float xpos, float ypos, float zpos)
        {
            position.X = xpos;
            position.Y = ypos;
            position.Z = zpos;
        }

        public void SetPosition(Vector3 pos)
        {
            position.X = pos.X;
            position.Y = pos.Y;
            position.Z = pos.Z;
        }


        public Vector3 GetPosition()
        {
            return position;
        }

      }
}
